package com.ruoyi.job.task;

import com.ruoyi.common.redis.service.RedisService;
import com.ruoyi.job.kettle.KettleQuartz;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

@Component("jxyjxx")
public class Jxyjxx {
    private Logger logger = LoggerFactory.getLogger(Jxyjxx.class);

    @Autowired
    private RedisService redisService;

    public void ryNoParams() {
        /**
         * 执行绩效业绩信息需要如下表入库
         *   QMCY_CUST_SJYH，DATA_GTGSH_YZ，jxxt.kjb
         */

        logger.info("开始执行绩效业绩信息定时任务===================");

        Date date=new Date();
        SimpleDateFormat sdf=new SimpleDateFormat("yyyyMMdd");
        String currentday=sdf.format(new Date(date.getTime()));

        String proKey = "proc-" + currentday + "-QMCY_CUST_JXYXYJB";
        if("0".equals(redisService.getCacheObject(proKey))) {
            logger.info("绩效业绩信息执行中");
        } else if("1".equals(redisService.getCacheObject((proKey)))) {
            logger.info("绩效业绩信息已执行完成");
        } else {
            boolean isTableSuccess = true;
            if(!"1".equals(redisService.getCacheObject(("authKey-" + currentday + "-QMCY_CUST_SJYH")))) {
                isTableSuccess = false;
            }
            if(!"1".equals(redisService.getCacheObject(("authKey-" + currentday + "-DATA_GTGSH_YZ")))) {
                isTableSuccess = false;
            }
            if(!"1".equals(redisService.getCacheObject(("authKey-" + currentday + "-jxxt")))) {
                isTableSuccess = false;
            }

            if (isTableSuccess) {
                redisService.setCacheObject(proKey, "0"); //执行中
                boolean bool = KettleQuartz.runKettleTransfer(null, "/home/ETLitem/QMCY_CUST_JXYXYJB.ktr");
                if(bool) {
                    redisService.setCacheObject(proKey, "1"); //执行完成
                    logger.info("存储执行完成");
                }
            } else {
                logger.info("数据未下发完整！");
            }

        }

        logger.info("结束执行绩效业绩信息定时任务===================");

    }
}
